﻿
using Coldairarrow.Business.Base_Leasesystem_equipment;
using Coldairarrow.Entity.Base_Leasesystem_equipment;
using Coldairarrow.Entity.ViewModel;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using NSwag.Annotations;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Base_Leasesystem_equipment
{
    /// <summary>
    /// 设备管理控制器
    /// </summary>
    [Route("/Base_Leasesystem_equipment/[controller]/[action]")]
    [OpenApiTag("设备管理控制器")]
    public class leasesystem_equipmentController : BaseApiController
    {
        #region DI



        public leasesystem_equipmentController(Ileasesystem_equipmentBusiness leasesystem_equipmentBus, IConfiguration configuration)
        {
            _leasesystem_equipmentBus = leasesystem_equipmentBus;
            _configuration = configuration;
        }
        readonly IConfiguration _configuration;
        Ileasesystem_equipmentBusiness _leasesystem_equipmentBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<leasesystem_equipment>> GetDataList(PageInput<ConditionDTO> input)
        {
            //var result = _leasesystem_equipmentBus.GetDataListAsync(input).select

            return await _leasesystem_equipmentBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<leasesystem_equipment> GetTheData(IdInputDTO input)
        {
            return await _leasesystem_equipmentBus.GetTheDataAsync(input.id);
        }

        /// <summary>
        /// 设备添加页面新增中得持有人下拉框
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public List<SelectModel> FullSelect()
        {
            return _leasesystem_equipmentBus.FullSelect();
        }

        /// <summary>
        /// 上传图片接口
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public object UpPhoto([FromForm] IFormFile file) 
        {
            var suffix = Path.GetExtension(file.FileName);//提取上传的文件文件后缀
            string guid = Util.ImgHelper.CreateTmpName();
            using (FileStream fs = System.IO.File.Create($@"{"D:/项目/estarting-two/AntdVue/src/Coldairarrow.Api/Upload"}\{guid}{suffix}"))//注意路径里面最好不要有中文
            {
                file.CopyTo(fs);//将上传的文件文件流，复制到fs中
                fs.Flush();//清空文件流
            }
            return StatusCode(200,new { newFileName = $"{"D:/项目/estarting-two/AntdVue/src/Coldairarrow.Api/Upload"}{guid}{suffix}" });//将新文件文件名回传给前端, new { newFileName = $"{combineId.LastId}{suffix}" }
        }

        /// <summary>
        /// 高级查询  
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<object> GetHeightSearch(PageInput<ConditionDTO> input)
        {
           return _leasesystem_equipmentBus.GetHeightSearch(input);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(leasesystem_equipment data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _leasesystem_equipmentBus.AddDataAsync(data);
            }
            else
            {
                await _leasesystem_equipmentBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        [ApiPermission("equipment.Delete")]
        public async Task DeleteData(List<string> ids)
        {
            await _leasesystem_equipmentBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}